﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LBoL.Base;
using LBoL.Base.Extensions;
using LBoL.ConfigData;
using LBoL.Core;
using LBoL.Core.Battle;
using LBoL.Core.Battle.BattleActions;
using LBoL.Core.Cards;
using LBoL.Core.StatusEffects;
using LBoL.Core.Units;
using LBoL.EntityLib.Cards.Character.Marisa;
using LBoL.EntityLib.Cards.Neutral.Blue;
using LBoLEntitySideloader.Attributes;
using ProbeMod.Cards.Template;

namespace ProbeMod.Cards
{
    public sealed class ProbeRecallDef : ProbeCardTemplate
    {
        public override CardConfig MakeConfig()
        {
            var config = GetCardDefaultConfig();

            config.TargetType = TargetType.Nobody;
            config.Type = CardType.Skill;
            config.Rarity = Rarity.Rare;

            config.Colors = new List<ManaColor>() { ManaColor.White };
            config.Cost = new ManaGroup() { White = 3 ,Any = 1 };
            config.UpgradedCost = new ManaGroup() { White = 2 };

            config.RelativeCards = new List<string>() { "ProbeZealotCharge" };
            config.Keywords = Keyword.Exile | Keyword.Retain;
            config.UpgradedKeywords = Keyword.Exile | Keyword.Retain;

            config.Index = CardIndexGenerator.GetUniqueIndex(config);

            return config;
        }
    }

    /// <summary>
    /// 群体召回
    ///     将放逐区中所有“狂热者冲锋”洗回弃牌堆
    /// </summary>
    [EntityLogic(typeof(ProbeRecallDef))]
    public sealed class ProbeRecall : ProbeCard
    {
        protected override IEnumerable<BattleAction> Actions(UnitSelector selector, ManaGroup consumingMana, Interaction precondition)
        {
            var zealotTemp = Library.CreateCard<ProbeZealotCharge>();

            if (!Battle.ExileZone.Any(x => x.Config.Id == zealotTemp.Config.Id))
            {
                yield return null;
            }

            //  洗狂热者

            var zealots = Battle.ExileZone.Where(x => x.Config.Id == zealotTemp.Config.Id).ToList();

            foreach (var zealot in zealots)
            {
                if(Battle.BattleShouldEnd)
                {
                    yield break;
                }
                yield return new MoveCardAction(zealot,CardZone.Discard);
            }
        }
    }
}
